/************************************************************************
 * 项目名称（软件名称）：忠旺机械物资管理系统(mms)                           *
 * 研发设计单位：忠旺机械设备制造有限公司机械设计院智能控制设计科设计与研发。   *
 * 版权所有：忠旺机械设备制造有限公司                                       *
 * 注：本项目的一切技术专利，使用规范归解释权由忠旺机械设备制造有限公司所有。   *
 * 软件版本：Ver 1.0.0                                                   *
 * 文件路径：com.zhongwang.mms.module.buy.controller                     *
 * 创建时间：2020年08月07日 18时27分                                       *
 *======================================================================*/
package com.zhongwang.mms.module.buy.service;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.zhongwang.mms.base.BaseService;
import com.zhongwang.mms.common.ImportCallBack;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.*;
import com.zhongwang.mms.gen.entity.VwPdmRepResult;
import com.zhongwang.mms.gen.mapper.BReportPlanMapper;
import com.zhongwang.mms.gen.mapper.VwPdmRepResultMapper;
import com.zhongwang.mms.module.basic.dao.TDictionaryDao;
import com.zhongwang.mms.module.basic.dao.TEmployDao;
import com.zhongwang.mms.module.buy.dao.ReportPlanDao;
import com.zhongwang.mms.module.buy.dao.VwPdmRepResultDao;
import com.zhongwang.mms.module.buy.listner.ReportPlanEditPlannerListener;
import com.zhongwang.mms.module.buy.model.*;
import com.zhongwang.mms.util.ExportExcelUtils;
import com.zhongwang.mms.util.FileUtils;
import com.zhongwang.mms.util.LogFormatUtil;
import com.zhongwang.mms.util.ShiroUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.*;


/**
 * @name: GetReportPlanApiService
 * @description: 对PDM系统接口业务逻辑层
 * @author: 徐一贺
 * @coddingDate: 2020/8/7 18:28
 * @version: v1.0
 **/
@Service
@Log4j2
public class GetReportPlanApiService extends BaseService {

    @Autowired
    private VwPdmRepResultDao vwPdmRepResultDao;
    @Autowired
    private TDictionaryDao tDictionaryDao;
    @Autowired
    private BReportPlanMapper bReportPlanMapper;
    @Autowired
    private TEmployDao tEmployDao;
    @Autowired
    private ReportPlanDao reportPlanDao;
    @Autowired
    private TEmployDao TEmployDao;


    @Value("${user.upload.path}")
    private String uploadPath;

    @Value("${controller.pdm.returnPlanUrl}")
    private String returnPlanUrl;

    /**
     * 信息变量
     */
    private String msg;
    @Autowired
    private VwPdmRepResultMapper vwPdmRepResultMapper;


    /**
     * @name: getToBeReceivedList
     * @description: 获取未接收列表
     * @param: [queryParam]
     * @returnType: java.util.List<com.zhongwang.mms.module.buy.model.ReceiveReportPlanModel>
     * @author: 徐一贺
     * @coddingDate: 2020/8/7 18:42
     * @version: v1.0
     **/
    public List<ReceiveReportPlanModel> getToBeReceivedList(ReceiveReportPlanModel queryParam) {
        return vwPdmRepResultDao.getToBeReceivedList(queryParam);
    }

    /**
     * @name: getReceivedList
     * @description: 获取已接收列表
     * @param: [queryParam]
     * @returnType: java.util.List<com.zhongwang.mms.module.buy.model.ReceiveReportPlanModel>
     * @author: 徐一贺
     * @coddingDate: 2025/12/2 14:20
     * @version: v1.0
     **/
    public List<ReceiveReportPlanModel> getReceivedList(ReceiveReportPlanModel queryParam) {
        return vwPdmRepResultDao.getReceivedList(queryParam);
    }
    /**
     * @name: receivePlans
     * @description: 批量接收
     * @param: [ids] 接收计划的ID
     * @returnType: com.zhongwang.mms.common.JsonResult
     * @author: 徐一贺
     * @coddingDate: 2020/8/7 19:36
     * @version: v1.0
     **/
//    @Transactional(rollbackFor = Exception.class)
    public JsonResult receivePlans(String ids) {
        JsonResult jsonResult = new JsonResult();
        try {
            Date currentDate = getDateTimeService.getSysDateTime();
            //lockTableBySQLServer("vw_pdm_rep_result","id",ids);
            List<ReceiveReportPlanModel> ReceiveReportPlanModels = vwPdmRepResultDao.getReceiveListByIds(ids);
            TEmployModel queryParam = new TEmployModel();
            queryParam.setEmpType(2);
            queryParam.setEmpStatus(1);
            List<TEmployModel> employList = tEmployDao.findListByCondition(queryParam);
            int planCount = 0;
            for (ReceiveReportPlanModel model : ReceiveReportPlanModels) {
                if (reportPlanDao.getReportPlanByRppResultId(model.getId()).size() == 0) {
                    BReportPlan reportPlan = new BReportPlan();
                    reportPlan.setRppProdNo(model.getProdNo());
                    reportPlan.setRppProjectCode(model.getProCode());
                    reportPlan.setRppProjectName(model.getProName());
                    reportPlan.setRppMatDesc(model.getMalDesc());
                    reportPlan.setRppNum(model.getNum().doubleValue());
                    reportPlan.setRppUnit(model.getUnit());
                    String dicRemark = "";
                    switch (model.getReportType()) {
                        case 1:
                            dicRemark = "外购件";
                            break;
                        case 2:
                            dicRemark = "外协件";
                            break;
                        case 3:
                            dicRemark = "原材料";
                            Random ra = new Random();
                            if (model.getUseStore() != null && model.getUseStore() == 1) {
                                reportPlan.setRppPlanner(employList.get(ra.nextInt(employList.size())).getEmpName());
                                reportPlan.setRppEditFlag(2);
                                reportPlan.setRppUseStock(1);
                            }
                            break;
                    }
                    TDictionary tDictionary = tDictionaryDao.getTDictionaryByDicReamrk(dicRemark);
                    reportPlan.setRppTypeId(tDictionary.getDicId());
                    reportPlan.setRppTypes(tDictionary.getDicName());
                    reportPlan.setRppPart(model.getPart());
                    reportPlan.setRppStandardNo(model.getStandard());
                    reportPlan.setRppBrand(model.getBrand());
                    reportPlan.setRppRemark(model.getRemark());
                    reportPlan.setRppUseStore(model.getUseStore());
                    reportPlan.setRppDiagram(model.getDiagram());
                    reportPlan.setRppAssistType(model.getAssistType());
                    reportPlan.setRppDesigner(model.getPostName());
                    reportPlan.setRppDesignerTel(model.getPostTel());
                    reportPlan.setRppDesignerDept(model.getPostDept());
                    reportPlan.setRppMalType(model.getMalType());
                    reportPlan.setRppResultId(model.getId());
                    reportPlan.setRppCreateUser(ShiroUtils.getUser().getName());
                    reportPlan.setRppCreateTime(currentDate);
                    reportPlan.setRppOriginalFlag(1);
                    reportPlan.setRppStatus(2);
                    if (reportPlan.getRppEditFlag() == null) {
                        reportPlan.setRppEditFlag(1);
                    }
                    reportPlan.setRppPostPlannerStatus(1);
                    reportPlan.setRppExtendUrl(model.getExtendUrl());
                    reportPlan.setRppRecTime(currentDate);
                    reportPlan.setRppIsFlag(0);
                    reportPlan.setRppSplitPlanType("source");
                    reportPlan.setRppBranchName(model.getBranchName());
                    if (reportPlanDao.getReportPlanByRppResultId(model.getId()).size() == 0) {
                        planCount++;
                        bReportPlanMapper.insert(reportPlan);

                    } else {
                        jsonResult.setType(JsonResult.ResultType.SUCCESS);
                        jsonResult.setMsg("接收提报计划成功！");
                        return jsonResult;
                    }
                }
                ReceiveReportPlanModel changeRecModel = new ReceiveReportPlanModel();
                changeRecModel.setId(model.getId());
                changeRecModel.setRecMark(1);
                changeRecModel.setRecTime(currentDate);
                vwPdmRepResultDao.updateSelectiveByPrimaryKey(changeRecModel);
                logService.saveLog("【采购管理-提报计划接收】", "共接收"+planCount+"条计划！");
                jsonResult.setType(JsonResult.ResultType.SUCCESS);
                jsonResult.setMsg("接收提报计划成功！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("接收提报计划失败！");
        }
        return jsonResult;
    }

    /**
     * @name: lockTableBySQLServer
     * @description: 锁表
     * @param: [tableName 表名, indexColumnName 主键, indexValue 主键值]
     * @returnType: boolean 返回是否成功
     * @author: 徐一贺
     * @coddingDate: 2020/8/7 20:37
     * @version: v1.0
     **/
    private boolean lockTableBySQLServer(String tableName, String indexColumnName, String indexValue) {
        try {
            LockTableModel lockTableModel = new LockTableModel();
            lockTableModel.setTableName(tableName);
            lockTableModel.setIndexColumnName(indexColumnName);
            lockTableModel.setIndexValue(indexValue);
            vwPdmRepResultDao.lockTableBySQLServer(lockTableModel);
        } catch (Exception exception) {
            log.error(exception.getMessage());
            return false;
        }
        return true;
    }


    /**
     * @name: lockTableBySQLServer
     * @description: 解锁表
     * @param: [tableName 表名, indexColumnName 主键, indexValue 主键值]
     * @returnType: boolean 返回是否成功
     * @author: 徐一贺
     * @coddingDate: 2020/8/7 20:37
     * @version: v1.0
     **/
    private boolean unLockTableBySQLServer(String tableName, String indexColumnName, String indexValue) {
        try {
            LockTableModel lockTableModel = new LockTableModel();
            lockTableModel.setTableName(tableName);
            lockTableModel.setIndexColumnName(indexColumnName);
            lockTableModel.setIndexValue(indexValue);
            vwPdmRepResultDao.unLockTableBySQLServer(lockTableModel);
        } catch (Exception exception) {
            log.error(exception.getMessage());
            return false;
        }
        return true;
    }

    /**
     * @name: editList
     * @description: 获取未编辑列表
     * @param: [queryParam]
     * @returnType: com.zhongwang.mms.common.JsonResult
     * @author: 徐一贺
     * @coddingDate: 2020/8/8 13:28
     * @version: v1.0
     **/
    public List<ReportPlanModel> getEditList(ReportPlanModel queryParam) {
        return reportPlanDao.findNotPostPlannerPlanList(queryParam);
    }

    /**
     * @name: editIsExits
     * @description: 验证计划员是否存在
     * @param: [planner] 计划员名称
     * @returnType: java.lang.String
     * @author: 徐一贺
     * @coddingDate: 2020/8/8 16:23
     * @version: v1.0
     **/
    public Boolean plannerIsExits(String planner) {
        TEmploy param = new TEmploy();
        param.setEmpName(planner);
        param.setEmpStatus(1);
        TEmploy tEmploy = tEmployDao.getByCondition(param);
        return tEmploy != null;
    }

    /**
     * @name: editSave
     * @description: 分配计划员和填写计划号
     * @param: [saveParam] 保存参数
     * @returnType: com.zhongwang.mms.common.JsonResult
     * @author: 徐一贺
     * @coddingDate: 2020/8/8 16:41
     * @version: v1.0
     **/
    public JsonResult savePlanner(ReportPlanModel saveParam) {
        JsonResult jsonResult = new JsonResult();
        try {
            BReportPlan before = reportPlanDao.getById(saveParam.getRppId());
            if (before.getRppPostPlannerStatus() == 1) {
                saveParam.setRppEditFlag(2);
                reportPlanDao.updatePlannerAndPlanNo(saveParam);
                jsonResult.setType(JsonResult.ResultType.SUCCESS);
                jsonResult.setMsg("分配成功！");
                BReportPlan after = reportPlanDao.getById(saveParam.getRppId());
                logService.saveLog("提报计划分配", "物料描述为：【" + after.getRppMatDesc() + "】的计划分配给计划员【" + after.getRppPlanner() + "】,计划号是：【" + after.getRppPlanNo()+"】");
            } else if (before.getRppPostPlannerStatus() == 2) {
                saveParam.setRppEditFlag(2);
                reportPlanDao.updatePlannerAndPlanNo(saveParam);
                jsonResult.setType(JsonResult.ResultType.SUCCESS);
                jsonResult.setMsg("重新分配成功！");
                BReportPlan after = reportPlanDao.getById(saveParam.getRppId());
                logService.saveLog("提报计划分配", "重新分配计划：项目号：【"+before.getRppProjectCode()+"】物料描述为：【" + before.getRppMatDesc() + "】的计划原来属于【" + before.getRppPlanner() + "】,计划号是：【" + before.getRppPlanNo()+"】。后重新分配给了计划员：【"+after.getRppPlanner()+"】,计划号是：【" + after.getRppPlanNo()+"】。");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("分配失败！");
        }
        return jsonResult;
    }

    /**
     * @name: editSubmit
     * @description: 批量提交
     * @param: [saveParam] 保存参数
     * @returnType: com.zhongwang.mms.common.JsonResult
     * @author: 徐一贺
     * @coddingDate: 2020/8/10 08:57
     * @version: v1.0
     **/
    public JsonResult editSubmit(ReportPlanModel submitParam) {
        JsonResult jsonResult = new JsonResult();
        try {
            submitParam.setRppPostPlannerStatus(2);
            submitParam.setRppStatus(2);
            reportPlanDao.updateRppPostPlannerStatus(submitParam);
            logService.saveLog("【采购管理-提报计划分配】", "批量提交成功！");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("提交成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("提交失败！");
        }
        return jsonResult;
    }

    /**
     * 列表 导出
     *
     * @param exportParam 导出条件
     * @return excel
     */
    public void exportExcel(HttpServletResponse response, ReportPlanModel exportParam) {
        List<ExportReportPlanEditModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        logService.saveLog("提报计划分配——导出","用户:【"+user.getName()+"】执行导出操作！");
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        exportParam.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        reportPlanDao.createExportTempTable(exportParam);
        //3.查询临时内存表数据导出
        Integer dataCount = reportPlanDao.getTempTableDataCount(exportParam);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + "计划员分配表.xls";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, ExportReportPlanEditModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                exportParam.setTopCount(topCount);
                exportParam.setNotHaveTopCount(notHaveTopCount);
                list = reportPlanDao.selectExportTempTableData(exportParam);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            reportPlanDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * @name: importExcel
     * @description: 导入
     * @param: [file]
     * @returnType: java.lang.String
     * @author: 徐一贺
     * @coddingDate: 2020/8/10 15:29
     * @version: v1.0
     **/
    public String importExcel(MultipartFile file) {
        try {
            FileUtils.importExcel(file, ExportReportPlanEditModel.class, new ReportPlanEditPlannerListener(reportPlanDao, new ImportCallBack() {
                @Override
                public void onSuccess() {
                    msg = "导入完成";
                }

                @Override
                public void onWarning(List list) {
                    msg = "部份数据无法导入，请点击下载检查数据内容";
                    exportErrorExcel(list);
                }
            }, reportPlanDao.findEmployByStatus(1)));
        } catch (Exception e) {
            return "导入失败";
        }
        logService.saveLog("提报计划编辑", "导入提报计划");
        return msg;
    }


    /**
     * 异常数据记录到数据库
     *
     * @param errorList
     */
    @Transactional(rollbackFor = Exception.class)
    public void exportErrorExcel(List<ExportReportPlanEditLogModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        for (int i = 0; i < errorList.size(); i++) {
            reportPlanDao.insertEditPlannerErrorLog(errorList.get(i));
        }
    }

    /**
     * @name: exportErrorLog
     * @description: 导出错误日志Excel
     * @param: [file]
     * @returnType: void
     * @author: 徐一贺
     * @coddingDate: 2020/8/10 15:28
     * @version: v1.0
     **/
    public void exportErrorLog(HttpServletResponse response) {
        ExportReportPlanEditLogModel exportParam = new ExportReportPlanEditLogModel();
        List<ExportReportPlanEditLogModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        exportParam.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        exportParam.setErrorUid(ShiroUtils.getUserId());
        reportPlanDao.createExportLogTempTable(exportParam);
        //3.查询临时内存表数据导出
        Integer dataCount = reportPlanDao.getTempTableLogDataCount(exportParam);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + "计划员分配错误信息表.xls";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, ExportReportPlanEditLogModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                exportParam.setTopCount(topCount);
                exportParam.setNotHaveTopCount(notHaveTopCount);
                list = reportPlanDao.selectExportTempTableLogData(exportParam);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            reportPlanDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * @name: getFilePathById
     * @description: 根据主键获取文件路径
     * @param: [id]
     * @returnType: java.lang.String
     * @author: 徐一贺
     * @coddingDate: 2020/8/15 9:22
     * @version: v1.0
     **/
    public String getFilePathById(Integer id, Integer recMark) {
        if (recMark == 1) {
            return vwPdmRepResultDao.getFilePathByRppResultId(id);
        } else {
            return vwPdmRepResultDao.getFilePathByPdmId(id);
        }

    }

    /**
     * @name: getFilePathByIdToChange
     * @description: 获取文件地址
     * @param: [id, dataType]
     * @returnType: java.lang.String
     * @author: 徐一贺
     * @coddingDate: 2020/8/17 12:59
     * @version: v1.0
     **/
    public String getFilePathByIdToChange(Integer id, String dataType) {
        String fileUrl = "";
        switch (dataType) {
            case "变更前":
            case "拆分记录":
                fileUrl = reportPlanDao.getById(id).getRppExtendUrl();
                break;
            default:
                fileUrl = vwPdmRepResultDao.getFilePathByPdmChangeId(id);
                break;
        }
        return fileUrl;
    }

    /**
     * @name: findVwDictCommonListByMat
     * @description: 获取物料类别
     * @param: []
     * @returnType: java.util.List<com.zhongwang.mms.gen.entity.VwDictCommon>
     * @author: 徐一贺
     * @coddingDate: 2020/8/26 13:44
     * @version: v1.0
     **/
    public List<VwDictCommon> findVwDictCommonListByMat() {
        return vwPdmRepResultDao.findVwDictCommonListByMat();
    }

    /**
     * @name: findVwDictCommonListByAssistTypes
     * @description: 获取外协类别
     * @param: []
     * @returnType: java.util.List<com.zhongwang.mms.gen.entity.VwDictCommon>
     * @author: 徐一贺
     * @coddingDate: 2020/8/26 13:44
     * @version: v1.0
     **/
    public List<VwDictCommon> findVwDictCommonListByAssistTypes() {
        return vwPdmRepResultDao.findVwDictCommonListByAssistTypes();
    }

    /**
     * @name: returnPlan
     * @description: 撤销已接收未提交的提报计划
     * @param: [id]
     * @returnType: com.zhongwang.mms.common.JsonResult
     * @author: 徐一贺
     * @coddingDate: 2020年11月5日17:58:44
     * @version: v1.0
     * @Remark: 我注释写这么细是为了备注
     **/
    @Transactional(rollbackFor = Exception.class)
    public JsonResult returnPlan(Integer id) {
        JsonResult jsonResult = new JsonResult();
        try {
            //获取计划对象用来记录日志
            VwPdmRepResult vwPdmRepResult = vwPdmRepResultDao.getVwPdmRepResultById(id);
            //防止重复提交，如果删除无法继续发送接口信号。
            if (vwPdmRepResult == null) {
                jsonResult.setType(JsonResult.ResultType.SUCCESS);
                jsonResult.setMsg("退回计划成功！");
            } else {
                //使用spring下的REST风格简单模板工具发送跨域http(超文本链接)访问
                RestTemplate restTemplate = new RestTemplate();
                //使用LinkedMultiValueMap创建用来存储一键多值情况的map对象
                MultiValueMap<String, Integer> map = new LinkedMultiValueMap<String, Integer>();
                //添加参数resultId其值是B表（PDM系统的数据库中的rep_result表）主键的值
                map.add("resultId", id);
                //提交的body内容为MultiValueMap对象，设置请求的返回的类型为Boolean，成功返回ture，失败返回false
                ResponseEntity<Boolean> responseEntity = restTemplate.postForEntity(returnPlanUrl, map, Boolean.class);
                if (responseEntity.getBody()) {
                    jsonResult.setType(JsonResult.ResultType.SUCCESS);
                    jsonResult.setMsg("退回计划成功！");
                    logService.saveLog("提报计划接收", "执行退回计划，项目号：【" + vwPdmRepResult.getProCode() + "】,物料描述:【" + vwPdmRepResult.getMalDesc() + "】,数量：【" + vwPdmRepResult.getNum() + "】,单位：【" + vwPdmRepResult.getUnit() + "】。");
                } else {
                    jsonResult.setType(JsonResult.ResultType.ERROR);
                    jsonResult.setMsg("退回计划失败，请联系管理员！");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("删除失败！");
        }
        return jsonResult;
    }

    /**
     * @title: getReportPlanByPrimaryKey
     * @description: 根据主键获取提报计划
     * @param: [id]
     * @return: com.zhongwang.mms.gen.entity.BReportPlan
     * @author: 徐一贺
     * @date: 2020/10/22 15:12
     * @versron: ver 1.0
     */
    public BReportPlan getReportPlanByPrimaryKey(Integer id) {
        return reportPlanDao.getReportPlanByPrimaryKey(id);
    }

    /**
     * 分页查询提报计划
     * @param pageNum
     * @param pageSize
     * @param queryParam
     * @return
     */
    public List<ExportRecPlanModel> queryReceivedSubmissionPlan(Integer pageNum, Integer pageSize,ReceiveReportPlanModel queryParam) {
        queryParam.setPageNum(pageNum);
        queryParam.setPageSize(pageSize);
        return reportPlanDao.queryReceivedSubmissionPlan(queryParam);
    }
}
